package com.yungu.swift.report.controller;

import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.admin.AdminReportParam;
import com.yungu.swift.report.entity.ReportFinanceFlowDriverDay;
import com.yungu.swift.report.service.FinanceFlowDriverDayService;
import com.yungu.swift.report.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author Zerrion
 * @version 1.0
 * @description 司机流水控制器
 * @date 2018/5/15 14:36
 */
@Slf4j
@RestController
@Api(value = "【司机流水统计】", tags = "司机流水统计")
public class FinanceFlowDriverDayCtrl {

    @Autowired
    private FinanceFlowDriverDayService financeFlowDriverDayService;

    @PostMapping("/report/financeFlowDriver/queryPageIndex")
    @ApiOperation(value = "司机流水分页统计", httpMethod = "POST")
    public ResponseData<Map<String, Object>> queryPageIndex(@RequestBody AdminReportParam reportParam) {
        return financeFlowDriverDayService.queryPage(reportParam);
    }

    @PostMapping("/report/financeFlowDriver/export")
    @ApiOperation(value = "司机流水统计导出", httpMethod = "POST")
    public void mileageExport(@RequestBody AdminReportParam reportParam, HttpServletResponse response) throws Exception {
        List<ReportFinanceFlowDriverDay> list = financeFlowDriverDayService.list(reportParam).getData();
        if (CollectionUtils.isEmpty(list)) {
            log.warn("{} 报表,没有统计数据可导出", "司机流水");
        }
        ExcelUtil.download(reportParam, response, list, ReportFinanceFlowDriverDay.class,
                "/template/finance_flow_driver_report.xlsx", "司机流水");
    }
}
